<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
    <script src="http://cdn.staticfile.org/semantic-ui/2.2.7/semantic.min.js"></script>
    <!--    <link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.min.css">-->
    <link href="http://cdn.staticfile.org/semantic-ui/2.4.1/semantic.min.css" rel="stylesheet">

</head>
<body>
<div class="ui secondary  menu">
    <a class="item" href="/home"><i class="home icon"></i>
        主页
    </a>
    <a class="item" href="/progress"><i class="space shuttle icon"></i>
        进程管理
    </a>
    <a class="item" href="/task"><i class="tasks plane icon"></i>
        作业调度
    </a>
    <a class="item" href="{% url 'test_list' %}"><i class="database icon"></i>
        存储管理
    </a>
    <a class="active item" href="/disk"><i class="box icon"></i>
        磁盘调度
    </a>
</div>

<hr class="half-rule">

<div class="ui container">
    <div class="ui segment">
        <div class="ui segment">
            <div class="ui purple progress" data-value="0" data-total="200" id="progress">
                <div class="bar">
                </div>
                <div class="label">磁盘扫描顺序</div>
            </div>
        </div>

        <div class="ui divider"></div>
        <div class="ui segment">
            <div class="ui fluid grid">
                <div class="four wide column">
                    <div class="ui left icon fluid input ">
                        <input type="text" id="allnum" placeholder="总磁道数...(默认200)">
                        <i class="hdd icon"></i>
                    </div>
                </div>

                <div class="four wide column">
                    <div class="ui left icon fluid input">
                        <input type="text" id="startnum" placeholder="开始磁道数...(默认100)">
                        <i class="studiovinari icon"></i>
                    </div>
                </div>
                <div class="four wide column">
                    <div class="ui fluid selection dropdown">
                        <input type="hidden" name="gender" id="gender">
                        <i class="dropdown icon"></i>
                        <div class="default text">方法选择</div>
                        <div class="menu">
                            <div class="item" data-value="FCFS" data-text="FCFS">
                                FCFS
                            </div>
                            <div class="item" data-value="SSTF" data-text="SSTF">
                                SSTF
                            </div>
                            <div class="item" data-value="SCAN" data-text="SCAN">
                                SCAN
                            </div>
                            <div class="item" data-value="CSCAN" data-text="CSCAN">
                                CSCAN
                            </div>
                        </div>
                    </div>
                </div>
                <div class="two wide column">
                    <button class="ui fluid teal icon button increase" onclick="AutoDoing()">开始 <i
                            class="accessible icon icon"></i></button>
                </div>
                <div class="two wide column">
                    <button class="ui fluid pink icon button increase" onclick="Compare()">方法比较 <i
                            class="accessible icon icon"></i></button>
                </div>
            </div>
        </div>
        <div class="ui divider"></div>
        <div class="ui segment">
            <div class="ui form">
                <div class="field">
                    <label>随机产生的轨道序列</label>
                    <textarea id="text0" rows="1"></textarea>
                </div>
            </div>
        </div>
        <div class="ui segment">
            <div class="ui form">
                <div class="field">
                    <label>扫描顺序</label>
                    <textarea id="text" rows="1"></textarea>
                </div>
            </div>
        </div>
        <div class="ui segment">
            <div class="ui form">
                <div class="field">
                    <label>比较结果</label>
                    <textarea id="text2" rows="10"></textarea>
                </div>
            </div>
            <br>
            <div class="ui fluid grid">
                <div class="fourteen wide column"></div>
                <div class="two wide column">
                    <button class="ui fluid red icon button increase" onclick="ClearText()">清屏<i
                            class="accessible icon icon"></i></button>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    function AutoDoing() {
        var timesRun = 0;
        var interval = setInterval(function () {
                if (timesRun === 9) {
                    clearInterval(interval);
                }
                $.ajax({
                    type: "POST",
                    url: "http://127.0.0.1:8000/diskcalculate/",
                    data: {
                        allnum: $("#allnum").val(),
                        startnum: $("#startnum").val(),
                        func: $("#gender").val(),
                        timesrun: timesRun,
                    },
                    success: function (data) {
                        var msg = eval("(" + data + ")");
                        $('#progress').progress({
                                percent: msg["num"] / msg["all"] * 100,
                                total: msg["all"],
                                value: msg["num"],
                                text: {
                                    active: '正在扫描{total}号磁盘中的第{value}号'
                                }
                            }
                        );
                        document.getElementById("text").innerHTML = msg["ans"];
                        document.getElementById("text0").innerHTML = msg["origin"];
                        console.log("+++", msg["ans"]);
                    },
                    error: function (message) {
                        console.log(message);
                    }
                });
                timesRun += 1;
            }
            , 1000);
    }

    function Compare() {
        $.ajax({
            type: "POST",
            url: "http://127.0.0.1:8000/diskcompare/",
            data: {
                allnum: $("#allnum").val(),
                startnum: $("#startnum").val(),
            },
            success: function (data) {
                var msg = eval("(" + data + ")");

                document.getElementById("text2").innerHTML = msg["ans"];
                console.log("+++", msg["ans"]);
            },
            error: function (message) {
                console.log(message);
            }
        });
    }

    function ClearText() {
        document.getElementById("text0").innerHTML = "";
        document.getElementById("text").innerHTML = "";
        document.getElementById("text2").innerHTML = "";
    }

    $(document).ready(function () {
        $('.ui.dropdown')
            .dropdown();
    });


</script>

</body>

</html>